package com.ssm.service.impl;

import com.ssm.dao.DepartmentnameMapper;
import com.ssm.dao.DepartmentpeopleMapper;
import com.ssm.dao.UmStudentMapper;
import com.ssm.entity.*;
import com.ssm.entity.DepartmentpeopleDatailedent;
import com.ssm.service.DepartmentPeopleService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("departmentPeopleService")
public class DepartmentPeopleServiceImpl implements DepartmentPeopleService {
    protected Logger logger= LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);

    @Resource(name = "departmentpeopleMapper")
    private DepartmentpeopleMapper departmentpeopleMapper;
    @Resource(name = "umStudentMapper")
    private UmStudentMapper umStudentMapper;
    @Resource(name = "departmentnameMapper")
    private DepartmentnameMapper departmentnameMapper;
    @Override
    public List<Departmentpeople> listAllDepartmentpeople() {
        return departmentpeopleMapper.selectByExample(new DepartmentpeopleExample());
    }

    @Override
    public Integer createDepartmentPeople(Departmentpeople departmentpeople) {
        return departmentpeopleMapper.insert(departmentpeople);
    }

    @Override
    public Integer update(Departmentpeople departmentpeople) {
        return departmentpeopleMapper.updateByPrimaryKey(departmentpeople);
    }

    @Override
    public Integer deleteDepartmentPeople(int id) {
        return departmentpeopleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Departmentpeople getDepartmentPeople(int id) {
        return departmentpeopleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Departmentpeople> getDepartmentPeopleExple(DepartmentpeopleExample departmentpeopleExample) {
        return departmentpeopleMapper.selectByExample(departmentpeopleExample);
    }
    //成员详细列表
    public List<DepartmentpeopleDatailedent> DepartmentpeopleDetailed(){
        List<Departmentpeople> list=new ArrayList<>();
        list=listAllDepartmentpeople();
        List<DepartmentpeopleDatailedent> list1=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {

            Departmentpeople departmentpeople=list.get(i);
            if (departmentpeople.getPeopleid()==null) {
                continue;
            }
            logger.info("显示部门人数"+list.size());
            int j=departmentpeople.getId();
            logger.info("获取列表id"+j);
            int v=departmentpeople.getDepartmentnameid();
            logger.info("获取部门id"+v);
            UmStudent student=umStudentMapper.selectByPrimaryKey(j);
            Departmentname departmentname=departmentnameMapper.selectByPrimaryKey(v);
            DepartmentpeopleDatailedent departmentpeopleDatailedent=new DepartmentpeopleDatailedent();
            if(!(student==null)) {
                departmentpeopleDatailedent.setName(student.getName());
            }
            departmentpeopleDatailedent.setDepartmentpeopledatailed(departmentpeople.getPeopleid());
            departmentpeopleDatailedent.setDeparmentname(departmentname.getdepartmentname());
            list1.add(departmentpeopleDatailedent);
            logger.info("获取"+list1);
        }
        return list1;
    }
}


